subroutine DIFF1D   
DIMENSION TN(41),DUM(41), TD(41), X(41), TE(41)
      OPEN(1, FILE='DIFF.DAT')
      OPEN(6, FILE='DIFF.OUT')
      READ(1, *) JMAX, MAXEX, NMAX, ALPH, S, TMAX
      PI = 3.1415927
      JMAP = JMAX - 1
      AJM = JMAP
      DELX = 1./AJM
      DELT = DELX*DELX*S/ALPH
      WRITE(6,2)JMAX, MAXEX, NMAX, TMAX
2     FORMAT('  JMAX=',I5,'   NMAX=',I5,'   TMAX=',F8.2)
      WRITE(6,3)S,ALPH,DELT,DELX
3     FORMAT('  S=',F5.3, '   ALPH =',E10.3, '   DELT =',E10.3, '   DELX =', E10.3,//)
      WRITE(6,4)S
4     FORMAT(' FTCS(EXPLCIT) SCHEME,',5X,'  S = ', F5.3,//)
      
      DO 5 J = 1, JMAP
5     TN(J) = 0.
      N = 0
      T = 0
      SJ = 1.0 - 2.0*S
      
6     TN(1) = 1.
      TN(JMAX) = 1.
      IF(T .LT. 0.01) TN(1) = 0.5
      IF(T .LT. 0.01) TN(JMAX) = 0.5
      TD(1) = 100.*TN(1)
      TD(JMAX) = 100.*TN(JMAX)
      
      DO 7 J = 2, JMAP
      DUM(J) = SJ*TN(J) + S * (TN(J-1) +TN(J+1))
7     CONTINUE
      DO 8 J=2, JMAP
8     TN(J) = DUM(J)
      
      DO 9 J=2,JMAP
9     TD(J) = 100.*TN(J)
      T = T + DELT
      WRITE(6,10)T,(TD(J),J=1,JMAX)
10    FORMAT(' T= ',F5.0,'  TD=',11F6.2)
      
      IF(N .GE. NMAX) GOTO 11
      IF(T .LT. TMAX) GOTO 6
      
11    SUM = 0.
      DO 13 J=1,JMAX
      AJ = J - 1
      X(J) = DELX*AJ
      TE(J) = 100.
      DO 12 M=1,MAXEX
      AM = M
      DAM = (2.*AM - 1.)
      DXM = DAM*PI*X(J)
      DTM = -ALPH*DAM*DAM*PI*PI*T
      
      IF(DTM .LT. -87.)DTM = -87.0
12    TE(J) = TE(J) - 400./DAM/PI*SIN(DXM)*EXP(DTM)
      SUM = SUM + (TE(J) - TD(J))**2
13    CONTINUE
      WRITE(*,*)JMAX
      WRITE(6,14)T,(TE(J),J=1,JMAX)
14    FORMAT(/,'  T= ',F5.0,'  TE=',11F6.2,//)
      
      AVS = SUM/(1. + AJM)
      RMS = SQRT(AVS)
      WRITE(6,15)RMS
15    FORMAT('  RMS DIF = ',E11.4,//)
      STOP
      END SUBROUTINE
      
      